import axios from 'axios'

// 请求拦截器
let axiosurl = ""
if(process.env.NODE_ENV === 'development'){
    axiosurl = process.env.VUE_APP_API
}else{
    axiosurl = process.env.VUE_APP_API
}
// 创建axios 赋值给常量
const service = axios.create({
    baseURL:axiosurl
})
service.interceptors.request.use(function(config){
    return config
},function(error){
    return Promise.reject(error)
})

// 响应拦截器
service.interceptors.response.use(function(response){
    return response
},function(error){
    console.log("sd",error);
    if(error.response){
        switch(error.response.status){
            case 404:
                console.log("url信息有误");
                break
            case 500:
                console.log("服务器有误");
                break
            default:
                console.log("未知错误")
                break
        }
    }
   
    return Promise.reject(error)
})

export default service